﻿using System;

namespace FDEE.Model
{

    public class MIXRebarRecord : RebarBase
    {
        public MIXRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter, int quantity, eShapeType shapeConfg,
            int aa,int bb,int cc,int rr) 
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfg)
        {
            if (aa < 0 || bb < 0 || cc < 0 || rr < 0)
            {
                throw new Exception("MIX结果异常请查询原因！");
            }
            A = aa;
            B = bb;
            C = cc;
            this.r = RebarKnowledge.GerRadius(diameter);
            this.d = PublicEnumItems.GeteDBData(diameter.ToString());
            R = rr;
            if (shapeConfg == eShapeType.MIXA|| shapeConfg == eShapeType.MIXAR)
                Formula = "L=A+B+C-R/2-r/2-2d";
            else if (shapeConfg == eShapeType.MIXB)
                Formula = "L=A+B-R/2-d";
            else if (shapeConfg == eShapeType.MIXC || shapeConfg == eShapeType.MIXCR)
            {
                r = 0;
                Formula = "L=A+B+C-R/2-d";
            }
        }

        public override void SetLength()
        {
            if (ShapeConfg == eShapeType.MIXA || ShapeConfg == eShapeType.MIXAR)
                Length = Math.Round((A + B + C - 0.5 * R- 0.5 * r - 2* d) *0.001,3,MidpointRounding.AwayFromZero);
            else if (ShapeConfg == eShapeType.MIXB)
                Length = Math.Round((A + B - 0.5 * R - d) * 0.001, 3, MidpointRounding.AwayFromZero);
            else if (ShapeConfg == eShapeType.MIXC || ShapeConfg == eShapeType.MIXCR)
                Length = Math.Round((A + B + C - 0.5 * R - d) * 0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("MIX长度计算异常，请查找原因！");
            }
        }
    }

   
}
